#!/bin/bash
if [ ! -f ~/.scrshotrc ];then
	xmessage -center "No config file found!"
	echo "Please take a look about your ~/.scrshotrc"
fi;

cd ~
. ~/.scrshotrc

#Sample 
#URL=example.com
#HOST='host.ftp.example.com'
#USER='username'
#PSWD='password'
#R_DIR='directory/in/your/ftp'

echo "Select window"
scrot  -s -e 'mkdir -p /tmp/scrshot/;mv $f /tmp/scrshot; echo "$f" > /tmp/scrshot/name'
name=`cat /tmp/scrshot/name`

if [ ! -f /tmp/scrshot/name ];then
	echo "No screenshot!"
	xmessage -center "No screenshot taken!"
	exit 1
fi;

echo "Uploading file"
ftp-upload -h $HOST -u $USER --password $PSWD --dir $R_DIR /tmp/scrshot/$name

if [ $? -ne 0  ];then
	echo "File not uploaded!"
	xmessage -center "File not uploaded!"
else
	echo -n $URL/$name | xsel -ib
	xmessage -center "File successfuly uploaded"
	echo; echo -n "File successfuly uploaded:    ";echo $URL/$name
fi;
rm /tmp/scrshot/name
